@import '../../styles/common.less';
@import '../../styles//mixins/menu.less';
@import '../../internals/Ripple/styles/mixins.less';
@import './mixin.less';

//
// Sidenavs
// --------------------------------------------------

// Base class
// --------------------------------------------------
.rs-sidenav {
  transition: width @sidenav-collapse-transition-config;
  width: @sidenav-default-width;
  display: flex;
  flex-direction: column;
}

.rs-sidenav-nav {
  list-style: none;
  padding: 0;

  .rs-sidenav-item,
  .rs-dropdown-toggle,
  .rs-dropdown-item,
  .rs-dropdown-item-toggle {
    padding: @sidenav-padding-vertical @sidenav-padding-horizontal;
    transition: @nav-item-transition;
    border-radius: 0;
    color: inherit;

    .high-contrast-mode({
      transition: none;
    });
  }

  .rs-dropdown-item {
    display: block;
  }

  > .rs-sidenav-item,
  > .rs-dropdown {
    margin: 0 !important;
  }

  // <Dropdown> within <Sidenav>
  > .rs-dropdown {
    // Submenu toggle
    .rs-dropdown-item-toggle {
      display: block;
      width: 100%;
      text-align: start;
      background: none;
      padding-right: (@sidenav-padding-horizontal + @sidenav-dropdown-toggle-caret-width);
      position: relative;
      border-width: 0;

      .rs-sidenav-collapse-in & {
        padding-left: @sidenav-level2-retract;
      }

      &:focus {
        outline: 0;
      }

      &:focus-visible {
        .focus-ring(inset);

        .high-contrast-mode({
          .focus-ring(slim-inset);
        });

        z-index: 1;
      }

      // Submenu toggle icon
      &-icon {
        font-size: @sidenav-item-caret-size;
        position: absolute;
        right: @sidenav-padding-horizontal;
        top: @sidenav-children-padding-vertical;
        // width: auto;
        // height: @sidenav-dropdown-toggle-caret-width;
        // transform: rotate(90deg);
      }
    }

    // Expanded submenu toggle icon
    .rs-dropdown-item-expand-icon {
      transform: rotate(270deg);
    }

    // Collapse submenu toggle icon
    .rs-dropdown-item-collapse-icon {
      transform: rotate(90deg);
    }
  }

  .high-contrast-mode({
    .rs-dropdown-toggle,
    .rs-dropdown-menu {
      border: none;
    }
  });

  .rs-sidenav-item:focus-visible {
    .focus-ring(inset);

    .high-contrast-mode({
      .focus-ring(slim-inset);
    });

    z-index: 1;
  }

  > .rs-dropdown .rs-dropdown-menu-item-focus,
  > .rs-dropdown .rs-dropdown-item-active {
    font-weight: normal;
    background: transparent;
  }

  > .rs-dropdown .rs-dropdown-menu {
    transition: height @sidenav-collapse-transition-config;
  }

  > .rs-dropdown .rs-dropdown-toggle {
    height: auto;
    padding-right: (@sidenav-padding-horizontal + @sidenav-dropdown-toggle-caret-width);

    .rs-dropdown-toggle-caret {
      font-size: @sidenav-item-caret-size;
      right: @sidenav-padding-horizontal;
      top: @sidenav-padding-vertical;

      // Make Caret AngleRight direction at down.
      &[aria-label='angle-right'] {
        transform: rotate(90deg);
      }
    }
  }

  // Level1
  // -----------------
  > .rs-sidenav-item,
  > .rs-dropdown .rs-dropdown-toggle {
    font-size: @sidenav-level1-item-font-size;
    line-height: @sidenav-level1-item-line-height;
    padding-left: (@sidenav-padding-horizontal + @sidenav-icon-width + @sidenav-icon-spacing);
    width: 100%;
    white-space: normal;

    // Sidenav is usually placed by the left/right edge of the page
    // thus use an inset focus ring to prevent overflow clipping
    &:focus-visible {
      .focus-ring(inset);
    }

    > .rs-icon:not(.rs-dropdown-toggle-caret) {
      font-size: @sidenav-level1-item-font-size;
      margin-right: @sidenav-icon-spacing;
      position: absolute;
      left: @sidenav-padding-horizontal;
      top: @sidenav-padding-vertical;
      line-height: @sidenav-level1-item-line-height;
      height: @sidenav-level1-item-font-size;
    }
  }

  > .rs-dropdown-focus .rs-dropdown-toggle,
  .rs-dropdown-toggle:focus-visible {
    .focus-ring();

    .high-contrast-mode({
      .focus-ring(slim-inset);
    });

    z-index: 2;
  }
}

.rs-sidenav-item {
  position: relative;
  display: block;
  outline: 0;
  overflow: hidden;
  text-decoration: none;

  &:hover,
  &:focus {
    text-decoration: none;
  }

  &:focus-visible,
  &&-focus {
    .focus-ring(slim-inset);

    z-index: 2;
  }
}

// TODO Consider rename as sidenav-footer
.rs-sidenav-toggle {
  height: @sidenav-footer-height;
  border-top: 1px solid;
  margin-top: auto;

  &-button {
    float: right;
    width: @sidenav-compact-width;
    height: 100%;
    border: none;
    border-radius: 0;
    color: inherit;
  }
}

// Expanded styles
.rs-sidenav-collapse-in {
  width: @sidenav-collapse-in-width;

  //Nav item
  .rs-sidenav-item {
    border-radius: 0;
  }

  //Dropdown style rewrite
  .rs-dropdown {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;

    &-item:focus-visible,
    &-item-focus {
      .focus-ring(inset);

      background: none;
      z-index: 2;

      .high-contrast-mode({
        .focus-ring(slim-inset);
      });

      &.rs-dropdown-item-submenu {
        box-shadow: none;

        > .rs-dropdown-item-toggle {
          .focus-ring(inset);

          .high-contrast-mode({
            .focus-ring(slim-inset);
          });

          z-index: 2;
        }
      }
    }

    // Set  the ripple effect of items.
    &-item:not(.rs-dropdown-item-submenu),
    &-item-submenu > .rs-dropdown-item-toggle {
      .with-ripple();
    }

    // Remove the ripple effect of disabled items.
    &-item-disabled &-item::after {
      display: none;
    }

    // Setting icon to dropdown-caret.
    .rs-dropdown-toggle-caret::before,
    .rs-dropdown-item-toggle > .rs-dropdown-item-toggle-icon::before {
      display: none;
    }

    .rs-dropdown-toggle-caret,
    .rs-dropdown-item-toggle > .rs-dropdown-item-toggle-icon {
      transition: transform 0.3s linear;
    }

    // Expand
    &.rs-dropdown-expand .rs-dropdown-toggle-caret {
      transform: rotate(180deg);
    }

    // Dropdown menu
    .rs-dropdown-menu {
      .reset-sidenav-dropdown-menu();
    }

    // Submenu
    .rs-dropdown-item-submenu {
      padding: 0;

      &:hover {
        background-color: transparent;
      }
    }
  }

  //Ellipsis
  .rs-dropdown-item:not(.rs-dropdown-item-submenu),
  .rs-dropdown-menu .rs-dropdown-menu-toggle {
    width: 100%;
    white-space: normal;
  }

  // Expand && Collapse
  // Collapse
  .rs-dropdown-menu {
    overflow: hidden;
  }

  .rs-dropdown.rs-dropdown-collapse > .rs-dropdown-menu.rs-dropdown-menu-collapse-out,
  .rs-dropdown-item-submenu.rs-dropdown-item-collapse
    > .rs-dropdown-menu.rs-dropdown-menu-collapse-out {
    display: none;
  }

  .rs-dropdown.rs-dropdown-menu-collapse-in > .rs-dropdown-menu.dropdown-menu-collapse-in,
  .rs-dropdown-item-submenu.rs-dropdown-menu-collapse-in
    > .rs-dropdown-menu.rs-dropdown-menu-collapse-in {
    display: block;
  }

  // @warn Here we can only use absolute positioning because of the limitations of using <Dropdown/> component.

  .rs-dropdown-item-submenu {
    > .rs-dropdown-item-menu-icon {
      padding-top: @sidenav-children-padding-vertical;
      padding-bottom: @sidenav-children-padding-vertical;
      line-height: @line-height-base;
      width: @font-size-base;
      position: absolute;
      z-index: 1;
    }
  }

  // Level2
  // -----------------
  .rs-dropdown-item,
  .rs-dropdown-item-submenu > .rs-dropdown-item-toggle {
    padding: @sidenav-children-padding-vertical @sidenav-padding-horizontal
      @sidenav-children-padding-vertical @sidenav-level2-retract;
  }

  .rs-dropdown-item {
    .dropdown-menu-icon-left-position(@sidenav-level2-retract);
  }

  // Level3
  // -----------------
  .rs-dropdown-item .rs-dropdown-item:not(.rs-dropdown-item-submenu),
  .rs-dropdown-item-submenu > .rs-dropdown-menu .rs-dropdown-item-toggle {
    padding-left: @sidenav-level3-retract;
  }

  .rs-dropdown-item-submenu > .rs-dropdown-menu > .rs-dropdown-item {
    .dropdown-menu-icon-left-position(@sidenav-level3-retract);
  }
}

// Folded && Collapsing styles
.rs-sidenav-collapse-out {
  .rs-sidenav-item,
  .rs-dropdown .rs-dropdown-toggle {
    padding-right: 0;
    // fixed height
    height: @sidenav-item-height;
    // supplement padding
    padding-left: @sidenav-default-width;

    &:focus-visible {
      .focus-ring();

      .high-contrast-mode({
        .focus-ring(slim-inset);
      });
    }
  }

  // The same to the dropdown item
  .rs-dropdown-item {
    @padding-right: @dropdown-item-padding-x+ @dropdown-item-submenu-icon-angle-spacing +
      @dropdown-item-submenu-icon-angle-width;

    padding: @dropdown-item-padding-y @padding-right @dropdown-item-padding-y
      @dropdown-item-padding-x;
  }

  .rs-dropdown-item-submenu {
    padding: 0;
  }

  .rs-dropdown-toggle-caret {
    display: none;
  }

  // Folded text animation setting
  .rs-sidenav-item-text,
  .rs-dropdown-toggle > span {
    animation: sideNavFoldedText @sidenav-collapse-transition-config forwards;
  }
}

// Collapsing styles
.rs-sidenav-collapsing {
  // Rewrite  text-overflow
  &.rs-sidenav-collapse-in,
  &.rs-sidenav-collapse-out {
    .rs-sidenav-item,
    .rs-dropdown .rs-dropdown-toggle,
    .rs-dropdown-item,
    .rs-dropdown-item-submenu > .rs-dropdown-menu-toggle {
      white-space: nowrap;
      text-overflow: clip;
    }
  }

  &.rs-sidenav-collapse-in {
    .rs-dropdown-toggle-caret {
      display: none;
    }
  }

  // Make sure icon text-align center
  &.rs-sidenav-collapse-out {
    .rs-dropdown .rs-dropdown-menu {
      padding-left: @sidenav-default-width - @sidenav-level2-retract;
    }

    .rs-dropdown-item {
      animation: sideNavFoldedText @sidenav-collapse-transition-config;
    }
  }
}

// Alternate Sidenav
// --------------------------------------------------

// Default Sidenav
.rs-sidenav-default {
  background-color: var(--rs-sidenav-default-bg);
  color: var(--rs-sidenav-default-text);

  .rs-sidenav-item,
  .rs-dropdown-toggle,
  .rs-sidenav-toggle-button {
    background-color: var(--rs-sidenav-default-bg);
  }

  .rs-sidenav-item:hover,
  .rs-dropdown .rs-dropdown-toggle:hover,
  .rs-sidenav-toggle-button:hover,
  .rs-dropdown.rs-dropdown-open .rs-dropdown-toggle {
    background-color: var(--rs-sidenav-default-hover-bg);
    color: var(--rs-sidenav-default-hover-text);
  }

  .rs-sidenav-item.rs-sidenav-item-active,
  .rs-dropdown-item.rs-dropdown-item-active,
  .rs-dropdown.rs-dropdown-selected-within .rs-sidenav-item-icon {
    color: var(--rs-sidenav-default-selected-text);
  }

  .rs-sidenav-toggle {
    border-top-color: var(--rs-sidenav-default-footer-border);
  }

  // Collapsed
  &.rs-sidenav-collapse-out {
    .rs-dropdown-item.rs-dropdown-item-active {
      .menuitem-active();
    }
  }
}

.rs-sidenav-default.rs-sidenav-collapse-in,
.rs-sidenav-default.rs-sidenav-collapsing {
  .rs-dropdown-item > .rs-dropdown-menu-toggle,
  .rs-dropdown-item > .rs-dropdown-item-toggle {
    color: var(--rs-sidenav-default-text);

    &:hover,
    &:focus,
    &.rs-dropdown-item-focus {
      background-color: var(--rs-sidenav-default-hover-bg);
      color: var(--rs-sidenav-default-hover-text);
    }
  }

  // Reset active dropdown-item style
  .rs-sidenav-item.rs-sidenav-item-active,
  .rs-dropdown-menu > .rs-dropdown-item.rs-dropdown-item-active {
    color: var(--rs-sidenav-default-selected-text);

    .high-contrast-mode({
      text-decoration: underline;
    });
  }
}

.rs-sidenav-default.rs-sidenav-collapse-in,
.rs-sidenav-default.rs-sidenav-collapsing,
.rs-sidenav-default.rs-sidenav-collapse-out {
  // Set active Level1 style
  .rs-dropdown.rs-dropdown-selected-within .rs-sidenav-item-icon {
    color: var(--rs-sidenav-default-selected-text);
  }
}

// Inverse Sidenav
.rs-sidenav-inverse {
  background-color: var(--rs-sidenav-inverse-bg);
  color: var(--rs-sidenav-inverse-text);

  .rs-sidenav-item,
  .rs-dropdown .rs-dropdown-toggle,
  .rs-sidenav-toggle-button,
  .rs-dropdown-item-submenu:hover > .rs-dropdown-item-toggle {
    background-color: var(--rs-sidenav-inverse-bg);

    &:hover,
    &:focus {
      background-color: var(--rs-sidenav-inverse-hover-bg);
    }
  }

  .rs-dropdown-item,
  .rs-dropdown-item > .rs-dropdown-menu-toggle,
  .rs-dropdown-item > .rs-dropdown-item-toggle,
  .rs-sidenav-toggle-button {
    color: var(--rs-sidenav-inverse-text);

    &:hover,
    &:focus,
    &.rs-dropdown-item-focus {
      background-color: var(--rs-sidenav-inverse-hover-bg);
      color: var(--rs-sidenav-inverse-text);
    }
  }

  // Active
  .rs-sidenav-item.rs-sidenav-item-active,
  .rs-dropdown.rs-dropdown-selected-within .rs-dropdown-toggle {
    .high-contrast-mode({
      color: var(--rs-sidenav-inverse-selected-text);
    });
  }

  // Active
  .rs-dropdown.rs-dropdown-selected-within .rs-dropdown-toggle,
  .rs-sidenav-item,
  .rs-dropdown .rs-dropdown-toggle {
    color: var(--rs-sidenav-inverse-text);

    &:hover,
    &:focus,
    &.rs-dropdown-item-focus {
      color: var(--rs-sidenav-inverse-text);
    }
  }

  .rs-sidenav-item.rs-sidenav-item-active,
  .rs-dropdown-item.rs-dropdown-item-active {
    background-color: var(--rs-sidenav-inverse-selected-bg);
  }

  .rs-sidenav-toggle {
    border-top-color: var(--rs-sidenav-inverse-footer-border);
  }
}

// Subtle Sidenav
.rs-sidenav-subtle {
  background-color: transparent;

  .rs-sidenav-item,
  .rs-dropdown-toggle,
  .rs-dropdown-item,
  .rs-sidenav-toggle-button {
    background-color: transparent;
    color: var(--rs-sidenav-subtle-text);

    &:hover,
    &:focus-visible {
      background-color: var(--rs-sidenav-subtle-hover-bg);
      color: var(--rs-sidenav-subtle-hover-text);
    }
  }

  // Active
  .rs-sidenav-item.rs-sidenav-item-active,
  .rs-dropdown-item.rs-dropdown-item-active,
  .rs-dropdown.rs-dropdown-selected-within .rs-sidenav-item-icon {
    color: var(--rs-sidenav-subtle-selected-text);
  }

  .rs-dropdown-open > .rs-dropdown-toggle.btn {
    background-color: transparent;

    &:hover,
    &:focus {
      background-color: var(--rs-sidenav-subtle-hover-bg);
    }
  }

  .rs-sidenav-toggle {
    border-top-color: var(--rs-sidenav-subtle-footer-border);
  }
}

.rs-sidenav-subtle.rs-sidenav-collapse-in,
.rs-sidenav-subtle.rs-sidenav-collapsing {
  .rs-dropdown-item > .rs-dropdown-menu-toggle,
  .rs-dropdown-item > .rs-dropdown-item-toggle {
    color: var(--rs-sidenav-subtle-text);

    &:hover,
    &:focus-visible {
      background-color: var(--rs-sidenav-subtle-hover-bg);
      color: var(--rs-sidenav-subtle-hover-text);
    }
  }

  // Reset active dropdown-item style
  .rs-dropdown-menu > .rs-dropdown-item.rs-dropdown-item-active {
    color: var(--rs-sidenav-subtle-selected-text);
  }
}

.rs-sidenav-subtle.rs-sidenav-collapse-in,
.rs-sidenav-subtle.rs-sidenav-collapsing,
.rs-sidenav-subtle.rs-sidenav-collapse-out {
  // Set active Level1 style
  .rs-dropdown.rs-dropdown-selected-within .rs-dropdown-toggle {
    &:hover {
      background-color: var(--rs-sidenav-subtle-hover-bg);
    }

    &-icon {
      color: var(--rs-sidenav-subtle-selected-text);
    }
  }
}

@keyframes sideNavFoldedText {
  0% {
    max-width: 200px;
    opacity: 0.8;
  }

  100% {
    max-width: 0;
    opacity: 0;
  }
}
